/**
 * Created by Administrator on 2018/11/24.
 */

// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('down3'),'macarons');

var seriesdata1 = [

    //
    //[
    //    55,42,50,52,49,75,42,50,60,55,50
    //],
    //[
    //    40,62,42,40,45,62,35,40,50,90,40
    //]
    [
        30,
        40,
        30,
        28,
        35,
        45,
        20,
        30,
        40,
        60,
        30
    ],
    [
        40,
        30,
        40,
        45,
        32,
        35,
        40,
        40,
        30
    ]
];
InitChart( seriesdata1);
function InitChart(value){
    // 指定图表的配置项和数据
    var option = {
        tooltip : {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        color:['#00ffff','#ffffc1'],
        legend:[

            {
                show:true,
                orient:'horizontal',
                x:'center',
                top:'3%',
                itemGap: 30,
                data:[
                    {
                        name:'XXXXX1',
                        icon:'bar'
                    },
                    {
                        name:'XXXXX2',
                        icon:'bar'
                    }
                ],
                textStyle:{
                    color:'#fff',
                    fontSize:40
                }
            }

        ],
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        grid: {
            left: '50',
            right: '80',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                //data:val,
                data:['2018/01','2018/02','2018/03','2018/04','2018/05','2018/06','2018/07'],
                axisLabel:{
                    show:true,
                    textStyle: {
                        color: '#fff',
                        fontSize:40
                    }
                },
                axisLine:{
                    lineStyle:{
                        color: '#56f0ed',
                        width:5
                    }
                }
            }
        ],
        yAxis :
        {
            name:'(%)',
            type : 'value',
            nameTextStyle:{
                color:"#fff",
                fontSize:40
            },
            min : 0,
            max:100,
            interval:10,
            axisLabel: {
                show: true,
                //interval: 'auto',
                //formatter: '{value}%',
                //position: 'left',
                //nameLocation: 'middle',
                //nameGap: 35,
                textStyle: {
                    color: '#fff',
                    fontSize:40
                }
            },
            show: true,
            splitLine:{
                show:false
            },
            axisLine:{
                lineStyle:{
                    color: '#56f0ed',
                    width:5
                }
            }
        },
        series : [
            {
                name:'XXXXX1',
                type:'line',
                symbol: 'circle',
                symbolSize:25, //拐点圆的大小
                //showSymbol: false,
                smooth:true,
                //stack: '总量',
                areaStyle: {
                    //color:'#00ffff'
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {
                        offset: 0,
                        color: 'rgb(0, 255, 255,0.9)'
                        },
                        {
                        offset: 1,
                        color: 'rgb(0, 255, 255, 0)'
                        }
                    ])
                },
                markLine: {
                    symbol: ['none', 'none'],//去掉箭头

                    silent: true,
                    itemStyle: {
                        normal: {
                            lineStyle: {width:1, type: 'solid', color:'#ccc' },
                            label: { show: true, position:'left' }
                        }
                    },
                    data:[
                        { name: '最小值',yAxis:0},
                        { name: '最大值',yAxis:80}
                    ]
                    //data:[{yAxis: 20},{yAxis: 40}]
                },
                data: value[0],

                lineStyle: {
                    normal: {
                        width: 10
                    }
                },
                itemStyle:{
                    normal: {
                        color: 'rgb(0, 255, 255)',
                        barBorderRadius: 5
                    }
                }
            },
            {
                name:'XXXXX2',
                type:'line',
                symbol: 'circle',
                symbolSize:25, //拐点圆的大小
                //showSymbol: false,
                smooth:true,
                //stack: '总量',
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {offset: 0,color: 'rgb(255, 255, 193)'},
                        {offset: 0.5,color: 'rgb(255, 255, 193,0.5)'},
                        {offset: 1,color: 'rgb(255, 255, 193, 0)'}

                    ])
                },
                markLine: {
                    symbol: ['none', 'none'],//去掉箭头

                    silent: true,
                    itemStyle: {
                        normal: {
                            lineStyle: {width:1, type: 'solid', color:'#ccc' },
                            label: { show: true, position:'left' }
                        }
                    },
                    //data:[{yAxis: 60},{yAxis: 80},{yAxis: 100}]
                },
                data: value[1],
                lineStyle: {
                    normal: {
                        width: 10
                    }
                },
                itemStyle:{
                    normal: {
                        color: 'rgb(255, 255, 211)',
                        barBorderRadius: 5
                    }
                }
            }
        ]
    };
// 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    window.onresize = function() {//监听div和屏幕的改变
        myChart.resize();//resize属性指定一个元素是否是由用户调整大小的。
    }
}
setInterval(function() {
    var op = myChart.getOption();
    var data0 = op.series[0].data;
    console.log(data0);
    var data1 = op.series[1].data;
    op.series[0].data.push(data0.shift());
    op.series[1].data.push(data1.shift());
    //data0.shift();
    //data1.shift();
    //op.xAxis[0].data.shift();
    myChart.setOption(op);
}, 5000);

